package com.cet.programmercarl.algorithmperformancanalysis.数组;

/**
 * @program: algorithm
 * @description:
 * @author: 陈恩涛
 * @create: 2022-03-09 12:01
 **/
public class LC844 {

    public static boolean backspaceCompare(String s, String t) { int slowIndex1 = 0, slowIndex2 = 0;
        char[] sCharArray = s.toCharArray();
        char[] tCharArray = t.toCharArray();
        for (int fastIndex = 0; fastIndex < sCharArray.length; fastIndex++) {
            if (sCharArray[fastIndex] != '#') {
                sCharArray[slowIndex1++] = sCharArray[fastIndex];
            } else {
                slowIndex1 --;
            }
        }
        for (int fastIndex = 0; fastIndex < tCharArray.length; fastIndex++) {
            if(tCharArray[fastIndex] != '#'){
                tCharArray[slowIndex2++] = tCharArray[fastIndex];
            } else {
                slowIndex2--;
            }
        }
        if (slowIndex1 != slowIndex2) {
            return false;
        } else {
            for (int i = 0; i < slowIndex1; i++) {
                if (sCharArray[i] != tCharArray[i]) {
                    return false;
                }
            }
        }
        return true;
    }

    public static void main(String[] args) {
        String s = "ab#c";
        String t = "ac";
        System.out.println(backspaceCompare(s, t));
    }
}
